#include "MemoryAU.h"
#include "CPU.h"
#include <iostream>

using namespace std;

	CPU* MemoryAU::cpu;
	short MemoryAU::RA_Pointer;
	short MemoryAU::RB_Pointer;
	short MemoryAU::RC_Pointer;

MemoryAU::MemoryAU()
{
}

MemoryAU::~MemoryAU()
{
}

void MemoryAU::setCPU(CPU* proc)
{
	cpu = proc;
}

void MemoryAU::loadParamVII()
{
	short inst = cpu->getIR();
	RA_Pointer = (inst & 0x0038) >>3;
//	cout << "Pointer A: " << RA_Pointer << endl;
	RB_Pointer = (inst & 0x0007);
//	cout << "Pointer B: " << RB_Pointer << endl;
	RC_Pointer = (inst & 0x3800) >> 11;
//	cout << "Pointer C: " << RC_Pointer << endl;
}

void MemoryAU::Fload()
{
	MemoryAU::loadParamVII();
	cpu->setWBRegister(RC_Pointer);
	cpu->setWBValue(cpu->readMemory(cpu->readRegister(RA_Pointer)));
	cpu->setshallWB(true);
//	cpu->setRegister(RC_Pointer,cpu->readMemory(cpu->readRegister(RA_Pointer)));
}

void MemoryAU::Fstore()
{
	MemoryAU::loadParamVII();
	cpu->setMemory(cpu->readRegister(RA_Pointer),cpu->readRegister(RB_Pointer));
}
